import request from '@/utils/request'
import type { Student } from './model/model'
import type { ResultModel } from './model/model'

// 分页查询学生
export const getStudentsApi = (params: {
  name?: string
  degree?: number
  clazzId?: number
  page?: number
  pageSize?: number
}) => request.get<ResultModel>('/students', { params })

// 根据id删除学生（支持批量）
export const deleteStudentsApi = (ids: number[]) =>
  request.delete<ResultModel>(`/students/${ids.join(',')}`)

// 新增学生
export const addStudentApi = (student: Student) => request.post<ResultModel>('/students', student)

// 根据id查询学生
export const getStudentByIdApi = (id: number) => request.get<ResultModel>(`/students/${id}`)

// 更新学生信息
export const updateStudentApi = (student: Student) => request.put<ResultModel>('/students', student)

// 更新学生违纪分
export const updateStudentScoreApi = (id: number, score: number) =>
  request.put<ResultModel>(`/students/${id}/${score}`)

// 学生学历统计DTO
export interface DegreeCountDTO {
  degree: number
  count: number
}
// 班级学生数统计DTO - 修正为与后端匹配的结构
export interface StudentCountDTO {
  clazzName: string
  data: number
}
// 获取学生学历统计
export const getStudentDegreeDataApi = () =>
  request.get<DegreeCountDTO[]>('/students/report/studentDegreeData')
// 获取班级学生数统计
export const getStudentCountDataApi = () =>
  request.get<StudentCountDTO[]>('/students/report/studentCountData')
